Skip to content

Add native AST support for USING JAR/FILE/ARCHIVE in CREATE FUNCTION#7436

Merged
georgesittas merged 2 commits intotobymao:mainfrom
hashwnath:feat/7435-using-jar-ast
Apr 3, 2026
Merged

Add native AST support for USING JAR/FILE/ARCHIVE in CREATE FUNCTION#7436
georgesittas merged 2 commits intotobymao:mainfrom
hashwnath:feat/7435-using-jar-ast

Conversation

@hashwnath
Copy link
Copy Markdown
Contributor

Summary

  • Adds a UsingProperty AST node to represent USING JAR/FILE/ARCHIVE clauses in Hive/Spark CREATE FUNCTION statements
  • Parses these clauses into proper AST nodes instead of falling back to the Command expression
  • Enables programmatic inspection and modification of the resource type and path

Previously, CREATE FUNCTION my_func AS 'com.MyFunc' USING JAR 's3://path' would be parsed as a Command node with the entire SQL as a raw string. Now it produces a proper Create node with a UsingProperty that can be inspected and modified.

Test plan

  • Added tests for USING JAR, USING FILE, and USING ARCHIVE roundtrip parsing
  • Added tests for CREATE OR REPLACE TEMPORARY FUNCTION ... USING JAR
  • Added tests for programmatic AST construction and modification
  • All 1072 existing + new tests pass

Fixes #7435

Parse Hive/Spark CREATE FUNCTION ... USING JAR/FILE/ARCHIVE statements
into proper AST nodes instead of falling back to the Command expression.

This adds a UsingProperty node that allows programmatic inspection and
modification of the resource type and path in CREATE FUNCTION statements.

Fixes tobymao#7435
@georgesittas
Copy link
Copy Markdown
Collaborator

Hey @hashwnath, thanks for the PR. Can you please run make style to resolve any styling issues and push again?

Resolves formatting per `make style` as requested by maintainer.
Copy link
Copy Markdown
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get this in and take it to the finish line, thank you for the contribution!

Comment on lines +534 to +537
def usingproperty_sql(self, expression: exp.UsingProperty) -> str:
kind = expression.args.get("kind")
return f"USING {kind} {self.sql(expression, 'this')}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to generator.py, otherwise UsingProperty.sql() will crash.

Comment on lines +241 to +246
def _parse_using_property(self) -> exp.Property:
if self._match_texts(("JAR", "FILE", "ARCHIVE")):
kind = self._prev.text.upper()
return exp.UsingProperty(this=self._parse_string(), kind=kind)

return self._parse_property_assignment(exp.FileFormatProperty)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'm not sure if this is complete, as per Hive's docs:

CREATE FUNCTION [db_name.]function_name AS class_name
  [USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 'file_uri'] ];

@georgesittas georgesittas merged commit c25c443 into tobymao:main Apr 3, 2026
8 checks passed
georgesittas pushed a commit that referenced this pull request Apr 3, 2026
…TE FUNCTION (#7436)

* Add native AST support for USING JAR/FILE/ARCHIVE in CREATE FUNCTION

Parse Hive/Spark CREATE FUNCTION ... USING JAR/FILE/ARCHIVE statements
into proper AST nodes instead of falling back to the Command expression.

This adds a UsingProperty node that allows programmatic inspection and
modification of the resource type and path in CREATE FUNCTION statements.

Fixes #7435

* style: run ruff-format on test_hive.py

Resolves formatting per `make style` as requested by maintainer.

Signed-off-by: George Sittas <giwrgos.sittas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support USING JAR more natively

2 participants